package com.jianhua.appmarket.common.util.encrypt;


import java.io.UnsupportedEncodingException;

public class RSAUtils {

	public static final String ECB_PKCS1_PADDING = "RSA/ECB/PKCS1Padding";//加密填充方式
    /**
     * RSA加密
     * @param enString 需要加密字符串
     * @param publicKey 加密的公钥
     * @return
     */
    public static String encrypt(String enString, byte[] publicKey) {
        try {
            byte[] data = enString.getBytes("UTF-8");
            return EncryptUtils.encryptRSA2HexString(data, publicKey, true, ECB_PKCS1_PADDING);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return "";
    }

    /**
     * RSA解密
     * @param denString
     *  @param privateKey 解密的私钥
     * @return
     */
    public static String dencrypt(String denString, byte[] privateKey) {
        try {
            byte[] bytesResult = EncryptUtils.decryptHexStringRSA(denString, privateKey, false, ECB_PKCS1_PADDING);
            return new String(bytesResult);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
}